package com.version1.diabeco.ui.peso;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.version1.diabeco.ActivityMain;
import com.version1.diabeco.R;
import com.version1.diabeco.model.peso.Peso;

/**
 * Adapter para visualizacion de registros en ListView con el siguiente formato: 
 * 
 * [Imagen] [Peso] [Unidad]
 * [Fecha] [Hora]
 * 
 */
public class PesoAdapter extends ArrayAdapter<Peso> {
	private final Context context;
	private final List<Peso> values;

	public PesoAdapter(Context context, int resource, List<Peso> values) {
		super(context, resource, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.activity_peso_fila, parent, false);
		
		Peso peso = values.get(position);
		
		TextView textView = (TextView) rowView.findViewById(R.id.textViewPesoFilaFecha);
		textView.setText(ActivityMain.DATE_FORMAT.format(peso.getFecha()));
		
		textView = (TextView) rowView.findViewById(R.id.textViewPesoFilaHora);
		textView.setText(ActivityMain.TIME_FORMAT.format(peso.getFecha()));
		
		textView = (TextView) rowView.findViewById(R.id.textViewPesoFilaPeso);
		textView.setText(peso.getPeso().toString());

		textView = (TextView) rowView.findViewById(R.id.textViewPesoFilaUnidad);
		textView.setText(peso.getUm());

		textView = (TextView) rowView.findViewById(R.id.textViewPesoFilaImc);
		textView.setText(peso.getImc().toString());

		textView = (TextView) rowView.findViewById(R.id.textViewPesoFilaImcTipo);
		textView.setText(peso.getImcTipo());
		
		return rowView;
	}
}
